home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Applications / Alpha.5.96 folder / Tcl / SystemCode / loadLaTeX.tcl < prev    next >
Encoding:
Text File  |  1994-09-18  |  5.9 KB  |  198 lines  |  [TEXT/ALFA]

  1. #############################################################################
  2. # Install the files that support one of the LaTeX modes.
  3. # The global flag $latexVersion indicates which mode (LaTeX 2.09 or LaTeX2e)
  4. # is currently installed.
  5. #
  6. # Author: Tom Pollard <pollard@cucbs.chem.columbia.edu>
  7. #
  8. proc loadLaTeX {} {
  9.     global HOME latexVersion
  10.     
  11.     set oldWd [pwd]
  12.     cd $HOME
  13.     
  14.     set latex209Dir ":LaTeX:latex 2.09"
  15.     set latex209Files {
  16.         {"latex.tcl" ":Tcl:SystemCode"}
  17.         {"latexMode.tcl" ":Tcl:SystemCode"}
  18.         {"LaTeX Help" ":Help"} 
  19.         {"LaTeX Key Bindings" ":Help"} 
  20.     }
  21.     set latex2eDir ":LaTeX:latex 2e"
  22.     set latex2eFiles {
  23.         {"latex.tcl" ":Tcl:SystemCode"} 
  24.         {"latexKeys.tcl" ":Tcl:SystemCode"} 
  25.         {"latexMenu.tcl" ":Tcl:SystemCode"} 
  26.         {"latexMode.tcl" ":Tcl:SystemCode"} 
  27.         {"LaTeX Help" ":Help"} 
  28.         {"LaTeX Key Bindings" ":Help"} 
  29.     }
  30.     set report 0
  31.         
  32.     if {$latexVersion == "2e"} {
  33.         if {[askyesno "Install LaTeX 2.09?"] == "yes"} {
  34.             set report [installFiles $latex209Dir $latex209Files $latex2eDir $latex2eFiles 1 TeX]
  35.             if {$report != 0} {
  36. # uncomment these lines if new files are not automatically sourced
  37. #                 alertnote "Now quit and restart Alpha to load LaTeX 2.09 mode"
  38. #                 set latexVersion "2.09"
  39. # and comment out this one
  40.                 alertnote "LaTeX 2.09 support was successfully installed"
  41. #
  42.             } else {
  43.                 alertnote "The installation was cancelled"
  44.             }
  45.         }
  46.     } elseif {$latexVersion == "2.09"} {
  47.         if {[askyesno "Install LaTeX 2e?"] == "yes"} {
  48.             set report [installFiles $latex2eDir $latex2eFiles $latex209Dir $latex209Files 1 TeX]
  49.             if {$report != 0} {
  50. # uncomment these lines if new files are not automatically sourced
  51. #                alertnote "Now quit and restart Alpha to load LaTeX2e mode"
  52. #                set latexVersion "2e"
  53. # and comment out this one
  54.                 alertnote "LaTeX2e support was successfully installed"
  55. #
  56.             } else {
  57.                 alertnote "The installation was cancelled"    
  58.             }
  59.         }
  60.     }
  61.     
  62.     if {$report != 0} {
  63.         set timePat {([0-9/]+) ([^:]+):([^:]+):([^:]+) (..)}
  64.         regsub $timePat [join [mtime [now] short]] {\1 \2.\3\5} timestamp
  65.         set fname "$HOME:LaTeX:Install Report $timestamp"
  66.         
  67.         set tmpfid [open $fname "w+"]
  68.         puts $tmpfid $report
  69.         close $tmpfid
  70.     }
  71.     
  72.     cd $oldWd
  73. }
  74.  
  75. ##############################################################################
  76. # Install a list of files from $InstallDir into various destination folders.
  77. #
  78. # Each item of $installList contains a list of two items : a file and its 
  79. # destination directory.  If $backupDir and $backupList are given, then the 
  80. # files from this list are first removed from the indicated directories and 
  81. # saved in $backupDir.  If $deleteOld is 1, then an old file is just
  82. # deleted if the backup directory doesn't exist or if it already contains
  83. # the file.
  84. #
  85. # If any Tcl source files (.tcl) are installed, then they are also automatically
  86. # sourced and "rebuildTclIndices" is called to update the autoloader index files.
  87. # Author: Tom Pollard <pollard@cucbs.chem.columbia.edu>
  88. #
  89. proc installFiles {installDir installList backupDir backupList 
  90.                    {deleteOld 0} {deleteBindings 0}} {
  91.     global HOME
  92.     set script {}
  93.     set report ""
  94.     set askedAlready 0
  95.     
  96.     set script2 {}
  97.     set report2 ""
  98.     
  99.     if {! [file exists $backupDir] && ! $deleteOld} {
  100.         lappend script [list mkdir $backupDir]
  101.         append report "Created backup directory \"$backupDir\"\n"
  102.     } 
  103.     
  104.     foreach item $backupList {
  105.         set file [lindex $item 0]
  106.         set dir [lindex $item 1]
  107.         
  108.         set frompath ${dir}:${file}
  109.         set topath ${backupDir}:${file}
  110.         
  111.         if {[file exists $frompath]} {
  112.             if {[file exists $topath]} {
  113.                 if {!$deleteOld && !$askedAlready} {
  114.                     if {[askyesno "Can I delete old files that are already backed up?"] == "yes"} {
  115.                         set deleteOld 1
  116.                     }
  117.                     set askedAlready 1
  118.                 }
  119.                 if {$deleteOld} {                    
  120.                     lappend script [list removeFile $frompath]
  121.                     append report "Deleted old file \"$file\" from folder \"$dir\"\n"
  122.  
  123.                 } elseif {[askyesno "Overwrite old backup file \"$file\"?"] == "yes"} {
  124.                     lappend script [list removeFile $topath]
  125.                     lappend script [list moveFile $frompath $topath]
  126.                     append report "Saved old file \"$file\" in folder \"$dir\"\n"
  127.                     
  128.                 } else {
  129.                     message "No files were moved or deleted"
  130.                     return 0
  131.                 }
  132.             } else {
  133.                 lappend script [list moveFile $frompath $topath]
  134.                 append report "Saved old file \"$file\" in folder \"$backupDir\"\n"
  135.             }
  136.         } else {
  137.             append report "-- old file \"$file\" was missing from folder \"$dir\" --\n"
  138.         }
  139.     }
  140.     
  141.     append report "\n"
  142.     
  143.     foreach item $installList {
  144.         set file [lindex $item 0]
  145.         set dir [lindex $item 1]
  146.         set frompath ${installDir}:${file}
  147.         set topath ${dir}:${file}
  148.         
  149.         if {[file exists $frompath]} {
  150.             lappend script [list copyFile $frompath $topath]
  151.             append report "Copied file \"$file\" from folder \"$installDir\" to \"$dir\"\n"
  152.             
  153.             if {[file extension $file] == ".tcl"} {
  154.                 lappend script2 [list uplevel {#0} [list source ${HOME}$topath]]
  155.                 append report2 "Loaded the new file \"$file\"\n"
  156.             }
  157.         } else {
  158.             message "Installation aborted - no files were moved or deleted"
  159.             alertnote "Install file \"$file\" is missing"
  160.             return 0
  161.         }
  162.     }
  163.  
  164.     if {[llength $script2]} {
  165. # comment out these lines to stop automatic sourcing of newly loaded .tcl files
  166. # (_Don't_ change the lines creating $script2, above)
  167.         if {$deleteBindings != 0} {
  168.             lappend script [list deleteModeBindings $deleteBindings]
  169.             append report "\nRemoved the old ${deleteBindings}-mode key bindings\n"
  170.         }
  171.         set script [concat $script $script2]
  172.         append report "\n"
  173.         append report $report2
  174. #
  175.         lappend script [list rebuildTclIndices]
  176.         append report "\nUpdated the auto-loader index files\n"
  177.     }
  178.     
  179. # # Uncomment these lines to get a play-by-play of the installation procedure 
  180. # #
  181. #    new -n "* Install Script *"
  182.     foreach item $script {
  183. #        insertText "$item\n"
  184.         eval $item
  185.     }
  186. #    catch {shrinkWindow 1}
  187. #    setWinInfo dirty 0
  188.     
  189.     new -n "* Installation Report *"
  190.     insertText $report
  191.     catch {shrinkWindow 1}
  192.     setWinInfo dirty 0
  193.     setWinInfo read-only 1
  194.  
  195.     return $report
  196. }
  197.